<?php

/**
*	Review Controller
*
*	This controller is used for the handling of any of the public pages and interfaces with the Display model.
*	
*/
class Review extends Controller {
	
	/**
	*	default function
	*
	*	This function loads when /review/ is called with no other arguments and loads the home view
	*
	*/
	function index() {
		$this->load->helper('url');
		
		$this->load->model('Display');
		$data['recent'] = $this->Display->get_recent(5);
		
		$this->load->view('home', $data);
	}
	
	/**
	*	Function: reviews
	*
	*	This function loads the reviews view which lists the series that have reviews entered for them
	*
	*	@param string $cat
	*	@param integer $id
	*	@param character $s
	*/
	function reviews($cat,$id,$s) {
		$this->load->helper('url');
		$this->load->model('Display');
		
		$data['list'] = $this->Display->list_reviewed($cat,$id,$s);
		// Below items used to format the URL for sorting
		$data['cat'] = $cat;
		$data['id'] = $id;
		$data['s'] = $s;
		
		$this->load->view('reviews', $data);
		
	}
	
	/**
	*	Function: series
	*
	*	This function loads the series view and displays the series information and all articles associated with the series
	*
	*	@param integer $id
	*/
	function series($id) {
		$this->load->helper('url');
		$this->load->model('Display');
		
		$data['series'] = $this->Display->get_series($id);
		$data['reviews'] = $this->Display->full_series($id);
		// We steal the name of the series here so we can use it in the browser window's title bar
		$data['pagetitle'] = $data['series']->name . " Reviews";
		
		$this->load->view('series', $data);

	}
	
	/**
	*	Function: series
	*
	*	This function loads the single article view which can be used for any of the different posts types (Misc/News/Review),
	*	as such it does some specific formatting depending on the type of article it is displaying.
	*
	*	@param integer $id
	*/
	function article($id) {
		$this->load->helper('url');
		$this->load->model('Display');
		
		$data['article'] = $this->Display->get_article($id);
		
		if(!is_null($data['article']->series)){
			$data['series'] = $this->Display->get_series($data['article']->series);
				
			if ($data['article']->episode == 0) {	// Check to see if its a series preview, an episode review, or complete review
				$data['pagetitle'] = $data['series']->name . " Preview";
			} else {
				if ($data['article']->episode == 99) {
					$data['pagetitle'] = $data['series']->name . " Complete Review";
				} else {
					$data['pagetitle'] = $data['series']->name . " Episode " . $data['article']->episode . " Review";
				}
			}
					
		} else if (strcmp($data['article']->class, "News") == 0) {	// Its news
			
			$data['pagetitle'] = "Site News";
		
		} else {
			$data['pagetitle'] = "Other Articles";
		}
		
		$this->load->view('article', $data);
		
	}
	
}

?>